layui.use(['layer','upload','layedit','treeSelect','table','form','laytpl','element'], function(){
    var $ = layui.$
        ,layer = layui.layer
        ,admin = layui.admin
        ,table = layui.table
        ,element = layui.element
        ,form = layui.form
        ,laytpl = layui.laytpl;
    var delFlag = null;
    var treeSelect= layui.treeSelect;//树形下拉框
    var upload = layui.upload;
    var layedit = layui.layedit;


    //回显数据
    var request = GetRequest();
    $.get("/log/analysejob/detail?id=" + request.id + "&indexName=" + request.indexName,function (data) {
        $("#jobid").val(data.jobid);
        $("#jobname").val(data.jobname);
        $("#jobtype option[value="+ data.jobtype +"]").attr("selected","selected");
        //加载业务线信息
        $.get('/log/analysejob/business/list',function (business) {
            $.each(business.data,function (i, ele) {
                if (ele.number == data.businessid) {
                    $("#businessid").append('<option selected="selected" value="'+ ele.number +'">'+ ele.name +'</option>');
                } else {
                    $("#businessid").append('<option value="'+ ele.number +'">'+ ele.name +'</option>');
                }
            });
            form.render('select');
        });
        $("#status").val(data.status);
        $("#status option[value="+ data.status +"]").attr("selected","selected");
        //当前用户
        $("#createuser").val(data.createuser);
        $("#remarks").val(data.remarks);
        form.render('select');
    });


    //修改产品分类信息
    form.on('submit(edit)', function(data){
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            url: '/log/analysejob/edit',
            data: data.field,
            type: 'post',
            success: function (data) {
                if(data.code == 200) {
                    top.layer.close(index);
                    top.layer.msg("修改成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                } else {
                    top.layer.close(index);
                    top.layer.msg("修改失败！");
                }
            },
            error:function () {
                top.layer.close(index);
                top.layer.msg("修改失败！");
            }
        });
        return false;
    });

    //获取路径中的参数
    function GetRequest() {
        var url = location.search;         //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

});

